﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class news_show : System.Web.UI.Page
{
    News n = new News();
    public static string TITLE;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            if (Request["id"] != null)
            {
                n.AddHit(int.Parse(Request["id"].ToString()));
                int id = Int32.Parse(Request["id"].ToString());
                this.Label1.Text = n.GetNewsById(id).Rows[0]["title"].ToString();
                this.Label2.Text = n.GetNewsById(id).Rows[0]["hit"].ToString();
                this.Label3.Text = Convert.ToDateTime(n.GetNewsById(id).Rows[0]["addtime"].ToString()).ToShortDateString().ToString();
                this.Label4.Text = n.GetNewsById(id).Rows[0]["content"].ToString();
                TITLE = n.GetNewsById(id).Rows[0]["title"].ToString() + "-" + Sysconfig.GetMainTitle();
                this.Label7.Text = "<a href='http://www.yc3m.com' target='_blank'><b>" + n.GetNewsById(id).Rows[0]["keyword"].ToString() + "</b></a>";
                if (n.GetNewsById(id).Rows[0]["pic"].ToString() != "")
                {
                    this.Image1.Visible = true;
                    this.Image1.ImageUrl = "/admin/" + n.GetNewsById(id).Rows[0]["pic"].ToString();
                }
                BindPreNews(Request["id"].ToString());
                BindNextNews(Request["id"].ToString());
            }
            else
                Response.Write("<script>alert('该ID号不存在或者已被删除');window.location='index.aspx'</script>");
        }
    }

    public void BindPreNews(string id)
    {
        DataTable dt = new DataTable();
        SqlHelper.FillDataTable("select * from news where id>" + id+" order by id", dt);
        if (dt.Rows.Count != 0)
            this.Label6.Text = "<a href='news_show.aspx?id=" + dt.Rows[0]["id"].ToString() + "' target='_blank' style='color:#94C501'>" + Function.GetSubstring(dt.Rows[0]["title"].ToString(),22) + "</a>";
        else
            this.Label6.Text = "没有了";
    }

    public void BindNextNews(string id)
    {
        DataTable dt = new DataTable();
        SqlHelper.FillDataTable("select * from news where id<" + id + " order by id desc", dt);
        if (dt.Rows.Count != 0)
            this.Label5.Text = "<a href='news_show.aspx?id=" + dt.Rows[0]["id"].ToString() + "' target='_blank' style='color:#94C501'>" + Function.GetSubstring(dt.Rows[0]["title"].ToString(), 22) + "</a>";
        else
            this.Label5.Text = "没有了";
    }
}
